
Ext.onReady(function(){
    var airNo = ""; //航班号
    var airNo2 = ""; //返程、联程航班号
    var airNo3 = "";
    var airNo4 = "";
    var fromto = ""; //城市对
    var fromto2 = ""; //返程、联程城市对
    var fromto3 = "";
    var fromto4 = "";
    var fly_date = ""; //起飞日期（年-月-日）
    var fly_date2 = ""; //返程、联程起飞日期
    var fly_date3 = "";
    var fly_date4 = "";
    var fly_time = ""; //起飞时间
    var fly_time2 = ""; //返程、联程起飞时间
    var fly_time3 = "";
    var fly_time4 = "";
    var arr_time = ""; //到达时间
    var arr_time2 = ""; //返程、联程到达时间
    var arr_time3 = "";
    var arr_time4 = "";
    var plane_type = ""; //机型
    var plane_type2 = ""; //返程、联程机型
    var plane_type3 = "";
    var plane_type4 = "";
    var price = ""; //价格
    var price2 = ""; //返程、联程价格
    var price3 = "";
    var price4 = "";
    var position = ""; //机票舱位
    var position2 = ""; //返程、联程机票舱位
    var position3 = "";
    var position4 = "";

    var from_id = "";
    var to_id = "";
    var to2_id = "";
    var mid_id = "";
    var zhida_checkbox = "D";
    var app_flag = ""; //是否是申请单
    var group_flag = ""; //是否是团体票
    var airportTpl = new Ext.XTemplate('<tpl for="."><div class="search-item">', '{airport_name}({airport_code})', '</div></tpl>');
    var airportStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: "/admin/getAllAirportComboBox"
        }),
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, [{
            name: 'id'
        }, {
            name: 'airport_name'
        }, {
            name: 'airport_code'
        }])
    });
    var fromAirport = new Ext.form.ComboBox({
        store: airportStore,
        fieldLabel: '出发地',
        name: 'from_airport',
        allowBlank: false,
        blankText: "出发地必须选择",
        emptyText: '请选择...',
        //typeAhead: false,
        loadingText: '搜索中...',
        //width: 200,
        anchor: '90%',
        //pageSize: 10,
        //hideTrigger: false,
        tpl: airportTpl,
        minChars: 0,
        itemSelector: 'div.search-item',
        onSelect: function(record){
            fromAirport.setValue(record.data.airport_name);
            from = record.data.airport_code;
            from_id = record.data.id;
            if (this.isExpanded()) {
                this.collapse();
            }
        }
    });
    fromAirport.on("focus",function(){
        this.selectText();
    });
    if (from_airport!=""){
        fromAirport.setValue(from_airport);
    }
    var toAirport = new Ext.form.ComboBox({
        store: airportStore,
        fieldLabel: '目的地',
        name: 'to_airport',
        allowBlank: false,
        blankText: "目的地必须选择",
        emptyText: '请选择...',
        //typeAhead: false,
        loadingText: '搜索中...',
        //width: 200,
        anchor: '90%',
        //pageSize: 10,
        //hideTrigger: false,
        tpl: airportTpl,
        minChars: 0,
        itemSelector: 'div.search-item',
        onSelect: function(record){
            toAirport.setValue(record.data.airport_name);
            to = record.data.airport_code;
            to_id = record.data.id;
            if (this.isExpanded()) {
                this.collapse();
            }
        }
    });
    toAirport.on("focus",function(){
        this.selectText();
    });
    if (to_airport!=""){
        toAirport.setValue(to_airport);
    }
    var to2Airport = new Ext.form.ComboBox({
        store: airportStore,
        fieldLabel: '终到地',
        name: 'to2_airport',
        allowBlank: true,
        blankText: "终到地地必须选择",
        emptyText: '请选择...',
        //typeAhead: false,
        loadingText: '搜索中...',
        //width: 200,
        anchor: '90%',
        //pageSize: 10,
        //hideTrigger: false,
        tpl: airportTpl,
        minChars: 0,
        itemSelector: 'div.search-item',
        onSelect: function(record){
            to2Airport.setValue(record.data.airport_name);
            to2 = record.data.airport_code;
            to2_id = record.data.id;
            if (this.isExpanded()) {
                this.collapse();
            }
        }
    });
    to2Airport.on("focus",function(){
        this.selectText();
    });
    if (to2_airport!=""){
        to2Airport.setValue(to2_airport);
    }
    var midAirport = new Ext.form.ComboBox({
        store: airportStore,
        fieldLabel: '目的地2',
        name: 'mid_airport',
        allowBlank: true,
        blankText: "目的地必须选择",
        emptyText: '请选择...',
        //typeAhead: false,
        loadingText: '搜索中...',
        //width: 200,
        anchor: '90%',
        //pageSize: 10,
        //hideTrigger: false,
        tpl: airportTpl,
        minChars: 0,
        itemSelector: 'div.search-item',
        onSelect: function(record){
            if (record.data.airport_name.indexOf("上海")<0){
                Ext.MessageBox.alert('提示', '中转地只能是上海');
            }else{
                midAirport.setValue(record.data.airport_name);
                mid = record.data.airport_code;
                mid_id = record.data.id;
            }
            if (this.isExpanded()) {
                this.collapse();
            }
        }
    });
    midAirport.on("focus",function(){
        this.selectText();
    });
    if (mid_airport!=""){
        midAirport.setValue(mid_airport);
    }
    var dateField = new Ext.form.DateField({
        fieldLabel: '出发日期',
        name: 'date',
        id: 'date_1',
        altFormats: 'Y-m-d',
        format: 'Y-m-d', //格式化日期
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "日期格式不对，正确格式为2008-01-01",
        allowBlank: false,
        //emptyText: '请选择...',
        inputType: '2008-01-01',
        //anchor: '50%',
        width: 90,
        vtype: 'daterange',
        endDateField: 'date_2',
        minValue: today,
        value: today
    });
    var date2Field = new Ext.form.DateField({
        fieldLabel: '返/联日期',
        name: 'date2',
        id: 'date_2',
        altFormats: 'Y-m-d',
        format: 'Y-m-d', //格式化日期
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "日期格式不对，正确格式为2008-01-01",
        allowBlank: true,
        //emptyText: '请选择...',
        inputType: '2008-01-01',
        //anchor: '50%',
        width: 90,
        vtype: 'daterange',
        startDateField: 'date_1',
        minValue: today
    //,value: today
    });
    var date3Field = new Ext.form.DateField({
        fieldLabel: '回程日期',
        name: 'date3',
        id: 'date_3',
        altFormats: 'Y-m-d',
        format: 'Y-m-d', //格式化日期
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "日期格式不对，正确格式为2008-01-01",
        allowBlank: true,
        //emptyText: '请选择...',
        inputType: '2008-01-01',
        //anchor: '50%',
        width: 90,
        vtype: 'daterange',
        endDateField: 'date_4',
        minValue: today
    //,value: today
    });
    var date4Field = new Ext.form.DateField({
        fieldLabel: '回程日期2',
        name: 'date4',
        id: 'date_4',
        altFormats: 'Y-m-d',
        format: 'Y-m-d', //格式化日期
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "日期格式不对，正确格式为2008-01-01",
        allowBlank: true,
        //emptyText: '请选择...',
        inputType: '2008-01-01',
        //anchor: '50%',
        width: 90,
        vtype: 'daterange',
        startDateField: 'date_3',
        minValue: today
    //,value: today
    });
    var airways = new Ext.form.ComboBox({
        store: new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: '/admin/getInternalAirways'
            }),
            reader: new Ext.data.JsonReader({
                root: 'root',
                id: 'id'
            }, ['id', 'airways_name', 'airways_code'])
        }),
        fieldLabel: "航空公司",
        name: 'airways',
        loadingText: '正在加载...',
        displayField: 'airways_name',
        valueField: 'airways_code',
        mode: 'remote',
        triggerAction: 'all',
        hiddenName: 'airways_code',
        emptyText: '所有',
        editable: false,
        allowBlank: true,
        width: 90,
        //maxHeight: 150,
        tabIndex: 4,
        value: airways_name
    });
    var dc = new Ext.form.Radio({
        //fieldLabel: '单程',
        hideLabel: true,
        name: 'trip_type',
        boxLabel: '单程',
        checked: dc_checked,
        inputValue: ''
    });
    var wf = new Ext.form.Radio({
        //fieldLabel: '往返',
        hideLabel: true,
        name: 'trip_type',
        boxLabel: '往返',
        checked: wf_checked,
        inputValue: 'wf'
    });
    var lc = new Ext.form.Radio({
        //fieldLabel: '联程',
        hideLabel: true,
        name: 'trip_type',
        boxLabel: '联程',
        checked: lc_checked,
        inputValue: 'lc'
    });
    var wflc = new Ext.form.Radio({
        //fieldLabel: '联程往返',
        hideLabel: true,
        name: 'trip_type',
        boxLabel: '联程往返',
        checked: wflc_checked,
        inputValue: 'wflc'
    });
    var starAir = new Ext.form.Checkbox({
        //fieldLabel: '*航班',
        hideLabel: true,
        name: 'star_air',
        boxLabel: '*航班',
        checked: false,
        anchor: '100%'
    });
    /*
     var zhida = new Ext.form.Checkbox({
     //fieldLabel: '直达',
     hideLabel: true,
     name: 'zhida',
     boxLabel: '直达',
     checked: true,
     anchor: '50%',
     value: 'D'
     });
     */
    dc.on('check', function(){
        if (dc.checked) {
            trip_type = "";
            to2Airport.allowBlank = true;
            date2Field.allowBlank = true;
            date3Field.allowBlank = true;
            date4Field.allowBlank = true;
            if (airlaneGridpanel2) {
                airlaneGridpanel2.setVisible(false);
            }
            airlaneGridpanel3.setVisible(false);
            airlaneGridpanel4.setVisible(false);
            Ext.getCmp('airport_to2_div').hide();
            Ext.getCmp('airport_mid_div').hide();
            Ext.getCmp('date2_div').hide();
            Ext.getCmp('date3_div').hide();
            Ext.getCmp('date4_div').hide();
            airlaneGridpanel.setHeight(460);
        }
    });
    wf.on('check', function(){
        if (wf.checked) {
            trip_type = "wf";
            to2Airport.allowBlank = true;
            date2Field.allowBlank = false;
            date3Field.allowBlank = true;
            date4Field.allowBlank = true;
            airlaneGridpanel2.setVisible(true);
            airlaneGridpanel3.setVisible(false);
            airlaneGridpanel4.setVisible(false);
            Ext.getCmp('airport_to2_div').hide();
            Ext.getCmp('airport_mid_div').hide();
            Ext.getCmp('date2_div').show();
            Ext.getCmp('date3_div').hide();
            Ext.getCmp('date4_div').hide();
            airlaneGridpanel.setHeight(250);
        }
    });
    lc.on('check', function(){
        if (lc.checked) {
            trip_type = "lc";
            to2Airport.allowBlank = false;
            date2Field.allowBlank = false;
            date3Field.allowBlank = true;
            date4Field.allowBlank = true;
            airlaneGridpanel2.setVisible(true);
            airlaneGridpanel3.setVisible(false);
            airlaneGridpanel4.setVisible(false);
            Ext.getCmp('airport_to2_div').show();
            Ext.getCmp('airport_mid_div').show();
            Ext.getCmp('date2_div').show();
            Ext.getCmp('date3_div').hide();
            Ext.getCmp('date4_div').hide();
            airlaneGridpanel.setHeight(250);
        }
    });
    wflc.on('check', function(){
        if (wflc.checked) {
            trip_type = "wflc";
            to2Airport.allowBlank = false;
            date2Field.allowBlank = false;
            date3Field.allowBlank = false;
            date4Field.allowBlank = false;
            airlaneGridpanel2.setVisible(true);
            airlaneGridpanel3.setVisible(true);
            airlaneGridpanel4.setVisible(true);
            Ext.getCmp('airport_to2_div').show();
            Ext.getCmp('airport_mid_div').show();
            Ext.getCmp('date2_div').show();
            Ext.getCmp('date3_div').show();
            Ext.getCmp('date4_div').show();
            airlaneGridpanel.setHeight(250);
        }
    });
    
    //提交按钮
    var searchButton = new Ext.Button({
        text: '开始查询',
        handler: function(){
            if (searchFormPanel.form.isValid()) {
                if (from==""){
                    Ext.MessageBox.alert('提示', '请选择出发地.');
                }else if (to == ""){
                    Ext.MessageBox.alert('提示', '请选择目的地.');
                }else if (to2 == "" && (lc.checked || wflc.checked)){
                    Ext.MessageBox.alert('提示', '请选择终到目的地.');
                }else{
                    //重置
                    airNo = ""; //航班号
                    airNo2 = ""; //返程、联程航班号
                    airNo3 = "";
                    airNo4 = "";
                    fly_time = ""; //起飞时间
                    fly_time2 = ""; //返程、联程起飞时间
                    fly_time3 = "";
                    fly_time4 = "";
                    arr_time = ""; //到达时间
                    arr_time2 = ""; //返程、联程到达时间
                    arr_time3 = "";
                    arr_time4 = "";
                    plane_type = ""; //机型
                    plane_type2 = ""; //返程、联程机型
                    plane_type3 = "";
                    plane_type4 = "";
                    price = ""; //价格
                    price2 = ""; //返程、联程价格
                    price3 = "";
                    price4 = "";
                    position = ""; //机票舱位
                    position2 = ""; //返程、联程机票舱位
                    position3 = "";
                    position4 = "";
                    //城市对
                    fromto = from + to;
                    fromto2 = "";
                    fromto3 = "";
                    fromto4 = "";
                    if (midAirport.getValue()==""){
                        mid = "";
                    }
                    if (dc.checked) {
                        trip_type = "";
                    }
                    else if (wf.checked) {
                        trip_type = "wf";
                        fromto2 = to + from;
                    }
                    else if (lc.checked) {
                        trip_type = "lc";
                        if (mid!=""){
                            fromto2 = mid + to2;
                        }else{
                            fromto2 = to + to2;
                        }
                    }
                    else if (wflc.checked) {
                        trip_type = "wflc";
                        if (mid!=""){
                            fromto2 = mid + to2;
                            fromto3 = to2 + mid;
                        }else{
                            fromto2 = to + to2;
                            fromto3 = to2 + to;
                        }
                        fromto4 = to + from;
                    }
                    //日期
                    fly_date = dateField.getValue().format('Y-m-d');
                    if (trip_type != "") {
                        fly_date2 = date2Field.getValue().format('Y-m-d');
                        if (trip_type == "wflc") {
                            fly_date3 = date3Field.getValue().format('Y-m-d');
                            fly_date4 = date4Field.getValue().format('Y-m-d');
                        }
                        else {
                            fly_date3 = "";
                            fly_date4 = "";
                        }
                    }
                    else {
                        fly_date2 = "";
                        fly_date3 = "";
                        fly_date4 = "";
                    }
                    //航空公司
                    if (airways_name!=airways.getValue()){
                        airways_code = airways.getValue();
                    }
                    if (starAir.checked) {
                        ds.baseParams.star = "yes";
                    }
                    else {
                        ds.baseParams.star = "";
                    }
                    if (trip_type == "wflc" && airways_code == "") {
                        Ext.Msg.alert('查询提示', '往返+联程只能定一个航空公司的航班');
                    }
                    else if (orderid != "" && airways_code == "" && (trip_type == "wf" || trip_type == "lc")) {
                        Ext.Msg.alert('查询提示', '修改航班只能定一个航空公司的航班');
                    }
                    else {
                        //转机联运信息
                        zjlyDS.baseParams.type = trip_type;
                        zjlyDS.baseParams.from = from_id;
                        zjlyDS.baseParams.to = to_id;
                        zjlyDS.baseParams.date = fly_date;
                        zjlyDS.baseParams.airways_code = airways_code;
                        zjlyDS.reload();
                        //直达航班
                        ds.baseParams.fromto = fromto;
                        ds.baseParams.date = fly_date;
                        ds.baseParams.zhida_checkbox = zhida_checkbox;
                        ds.baseParams.airways_code = airways_code;
                        ds.baseParams.trip_type = trip_type;
                        //alert(fromto + "," + fly_date + "," + fromto2 + "," + fly_date2 + "," + fromto3 + "," + fly_date3 + "," + fromto4 + "," + fly_date4 + "," + trip_type + "," + airways_code);
                        ds.reload({
                            callback: function(record, options, success){
                                //alert(success);
                                if (success) {
                                    //处理前一天,后一天时间和标题.
                                    upDate1.setText("前一天(" + getDateByNum(fly_date, -1) + ")");
                                    nextDate1.setText("后一天(" + getDateByNum(fly_date, 1) + ")");
                                    var root_length = this.reader.jsonData.root.length;
                                    //alert(root_length);
                                    if (root_length>0){
                                        if (trip_type != "") {
                                            reloadDS2();
                                        }
                                    }else{
                                        var result = this.reader.jsonData.info;
                                        if (result == "" || result == "successful") {
                                            Ext.Msg.alert('查询异常', '没有符合条件的航班');
                                        }else{
                                            Ext.MessageBox.alert("查询异常", "" + result);
                                        }
                                        searchZjlyAirLine();
                                    }
                                }
                                else {
                                    alert(this.reader.jsonData.root.length);
                                    Ext.Msg.alert('查询异常', '查询中断，请再尝试一次');
                                }
                            }
                        });
                    }
                }
            }
            else {
                Ext.MessageBox.alert('错误消息', '请将必填项信息录入后再提交.');
            }
        }
    });
    var itemsArr = [{
        layout: 'column',
        border: false,
        items: [{
            columnWidth: .3,
            layout: 'form',
            border: false,
            items: [fromAirport]
        }, {
            columnWidth: .18,
            labelWidth: 60,
            layout: 'form',
            border: false,
            items: [dateField]
        }, {
            columnWidth: .16,
            layout: 'form',
            border: false,
            items: [airways]
        }, {
            columnWidth: .24,
            layout: 'form',
            border: false,
            items: [{
                layout: 'column',
                border: false,
                items: [{
                    columnWidth: .2,
                    layout: 'form',
                    border: false,
                    items: [dc]
                }, {
                    columnWidth: .2,
                    layout: 'form',
                    border: false,
                    items: [wf]
                }, {
                    columnWidth: .2,
                    layout: 'form',
                    border: false,
                    items: [lc]
                }, {
                    columnWidth: .4,
                    layout: 'form',
                    border: false,
                    items: [wflc]
                }]
            }]
        }, {
            columnWidth: .12,
            layout: 'form',
            border: false,
            items: [starAir]
        }]
    }, {
        layout: 'column',
        border: false,
        items: [{
            columnWidth: .3,
            layout: 'form',
            border: false,
            items: [toAirport]
        }, {
            id: 'date2_div',
            columnWidth: .18,
            labelWidth: 60,
            layout: 'form',
            border: false,
            items: [date2Field]
        }, {
            id: 'airport_mid_div',
            columnWidth: .3,
            layout: 'form',
            border: false,
            items: [midAirport]
        }, {
            columnWidth: .2,
            layout: 'form',
            border: false,
            items: [searchButton]
        }]
    }, {
        id: 'airport_to2_div',
        layout: 'column',
        border: false,
        items: [{
            columnWidth: .3,
            layout: 'form',
            border: false,
            items: [to2Airport]
        }, {
            id: 'date3_div',
            columnWidth: .18,
            labelWidth: 60,
            layout: 'form',
            border: false,
            items: [date3Field]
        }, {
            id: 'date4_div',
            columnWidth: .25,
            labelWidth: 70,
            layout: 'form',
            border: false,
            items: [date4Field]
        }]
    }];

    var searchFormPanel;
    if (orderid == "") {
        searchFormPanel = new Ext.form.FormPanel({
            //baseCls: 'x-plain',
            labelWidth: 55,
            width: '100%',
            frame: true,
            labelAlign: 'right',
            items: itemsArr
        });
    }else{
        searchFormPanel = new Ext.form.FormPanel({
            title: '订单号：'+checkAir_order_no+' 客户：'+checkAir_customer_name,
            //baseCls: 'x-plain',
            labelWidth: 55,
            width: '100%',
            frame: true,
            labelAlign: 'right',
            items: itemsArr
        });
    }
    searchFormPanel.render('search_air_form');
    
    if (trip_type==""){
        Ext.getCmp('airport_to2_div').hide();
        Ext.getCmp('airport_mid_div').hide();
        Ext.getCmp('date2_div').hide();
        Ext.getCmp('date3_div').hide();
        Ext.getCmp('date4_div').hide();
    }else if (trip_type=="wf"){
        Ext.getCmp('airport_to2_div').hide();
        Ext.getCmp('airport_mid_div').hide();
        Ext.getCmp('date3_div').hide();
        Ext.getCmp('date4_div').hide();
        date2Field.allowBlank = false;
    }else if (trip_type=="lc"){
        Ext.getCmp('date3_div').hide();
        Ext.getCmp('date4_div').hide();
        to2Airport.allowBlank = false;
        date2Field.allowBlank = false;
    }else{
        to2Airport.allowBlank = false;
        date2Field.allowBlank = false;
        date3Field.allowBlank = false;
        date4Field.allowBlank = false;
    }

    function searchZjlyAirLine(){
        //alert(fromto+"-"+fly_date+"-"+airways_code);
        Ext.Ajax.request({
            url: '/index/searchZjlyAirLine',
            params: 'fromto='+fromto+'&date='+fly_date+'&airways_code='+airways_code,
            method: 'GET',
            success: function(result, request){
                Ext.MessageBox.alert('二次查询结果', result.responseText);
            },
            failure: function(result, request){
                Ext.MessageBox.alert('操作失败', '查询联程航班失败');
            }
        });
    }
    //往返或联程
    function reloadDS2(){
        ds2.baseParams.fromto = fromto2;
        ds2.baseParams.date = fly_date2;
        ds2.baseParams.zhida_checkbox = zhida_checkbox;
        ds2.baseParams.airways_code = airways_code;
        ds2.baseParams.trip_type = trip_type;
        ds2.reload({
            callback: function(record, options, success){
                if (success) {
                    //处理前一天,后一天时间和标题.
                    upDate2.setText("前一天(" + getDateByNum(fly_date2, -1) + ")");
                    nextDate2.setText("后一天(" + getDateByNum(fly_date2, 1) + ")");
                    var root_length = this.reader.jsonData.root.length;
                    if (root_length>0){
                        if (trip_type == "wflc") {
                            reloadDS3();
                        }
                    }else{
                        var result = this.reader.jsonData.info;
                        if (result == "" || result == "successful") {
                            Ext.Msg.alert('提示', '没有符合条件的航班');
                        }else{
                            Ext.MessageBox.alert("提示", "" + result);
                        }
                    }
                }
                else {
                    Ext.Msg.alert('查询异常', '联程查询中断，请再尝试一次');
                }
            }
        });
    }
    //往返+联程
    function reloadDS3(){
        ds3.baseParams.fromto = fromto3;
        ds3.baseParams.date = fly_date3;
        ds3.baseParams.zhida_checkbox = zhida_checkbox;
        ds3.baseParams.airways_code = airways_code;
        ds3.baseParams.trip_type = trip_type;
        ds3.reload({
            callback: function(record, options, success){
                if (success) {
                    upDate3.setText("前一天(" + getDateByNum(fly_date3, -1) + ")");
                    nextDate3.setText("后一天(" + getDateByNum(fly_date3, 1) + ")");
                    var root_length = this.reader.jsonData.root.length;
                    if (root_length>0){
                        ds4.baseParams.fromto = fromto4;
                        ds4.baseParams.date = fly_date4;
                        ds3.baseParams.zhida_checkbox = zhida_checkbox;
                        ds4.baseParams.airways_code = airways_code;
                        ds4.baseParams.trip_type = trip_type;
                        ds4.reload({
                            callback: function(record, options, success){
                                upDate4.setText("前一天(" + getDateByNum(fly_date4, -1) + ")");
                                nextDate4.setText("后一天(" + getDateByNum(fly_date4, 1) + ")");
                            }
                        });
                    }else{
                        var result = this.reader.jsonData.info;
                        if (result == "" || result == "successful") {
                            Ext.Msg.alert('提示', '没有符合条件的航班');
                        }else{
                            Ext.MessageBox.alert("提示", "" + result);
                        }
                    }
                }
                else {
                    Ext.Msg.alert('查询异常', '回程查询中断，请再尝试一次');
                }
            }
        });
    }
    //选中航班舱位订票
    clickOn = function(air_no_par, fromto_par, position_par, price_par, flyTime_par, arrTime_par, plane_par, num_par){
        if (num_par == "4") {
            airNo4 = air_no_par;
            position4 = position_par;
            price4 = price_par;
            fly_time4 = flyTime_par;
            arr_time4 = arrTime_par;
            plane_type4 = plane_par;
            if (airNo4.indexOf("*") == 0) {
                airNo4 = airNo4.substring(1);
            }
            fromto4 = fromto_par;
        }
        else if (num_par == "3") {
            airNo3 = air_no_par;
            position3 = position_par;
            price3 = price_par;
            fly_time3 = flyTime_par;
            arr_time3 = arrTime_par;
            plane_type3 = plane_par;
            if (airNo3.indexOf("*") == 0) {
                airNo3 = airNo3.substring(1);
            }
            fromto3 = fromto_par;
        }
        else if (num_par == "2") {
            airNo2 = air_no_par;
            position2 = position_par;
            price2 = price_par;
            fly_time2 = flyTime_par;
            arr_time2 = arrTime_par;
            plane_type2 = plane_par;
            if (airNo2.indexOf("*") == 0) {
                airNo2 = airNo2.substring(1);
            }
            fromto2 = fromto_par;
        }
        else {
            airNo = air_no_par;
            position = position_par;
            price = price_par;
            fly_time = flyTime_par;
            arr_time = arrTime_par;
            plane_type = plane_par;
            if (airNo.indexOf("*") == 0) {
                airNo = airNo.substring(1);
            }
            fromto = fromto_par;
        }
        ChooseTrip();
    }
    //pat:a查询价格
    clickOnPat = function(air_no_par, fromto_par, position_par, flyTime_par, arrTime_par, plane_par, num_par){
        var url = "/orders/clickTicketTypeProcess";
        if (num_par && num_par == "2") {
            airNo2 = air_no_par;
            position2 = position_par;
            price2 = "";
            fly_time2 = flyTime_par;
            arr_time2 = arrTime_par;
            plane_type2 = plane_par;
            if (airNo2.indexOf("*") == 0) {
                airNo2 = airNo2.substring(1);
            }
            fromto2 = fromto_par;
            url += "?grid_no=2&airNo=" + airNo2 + "&position=" + position2 + "&fromto=" + fromto2 + "&date=" + fly_date2 + "";
        }
        else if (num_par == "3") {
            airNo3 = air_no_par;
            position3 = position_par;
            price3 = "";
            fly_time3 = flyTime_par;
            arr_time3 = arrTime_par;
            plane_type3 = plane_par;
            if (airNo3.indexOf("*") == 0) {
                airNo3 = airNo3.substring(1);
            }
            fromto3 = fromto_par;
            url += "?grid_no=3&airNo=" + airNo3 + "&position=" + position3 + "&fromto=" + fromto3 + "&date=" + fly_date3 + "";
        }
        else if (num_par == "4") {
            airNo4 = air_no_par;
            position4 = position_par;
            price4 = "";
            fly_time4 = flyTime_par;
            arr_time4 = arrTime_par;
            plane_type4 = plane_par;
            if (airNo4.indexOf("*") == 0) {
                airNo4 = airNo4.substring(1);
            }
            fromto4 = fromto_par;
            url += "?grid_no=4&airNo=" + airNo4 + "&position=" + position4 + "&fromto=" + fromto4 + "&date=" + fly_date4 + "";
        }
        else {
            airNo = air_no_par;
            position = position_par;
            price = "";
            fly_time = flyTime_par;
            arr_time = arrTime_par;
            plane_type = plane_par;
            if (airNo.indexOf("*") == 0) {
                airNo = airNo.substring(1);
            }
            fromto = fromto_par;
            url += "?airNo=" + airNo + "&position=" + position + "&fromto=" + fromto + "&date=" + fly_date + "";
        }
        var singleClickWindow = new Ext.Window({
            layout: 'fit',
            width: 360,
            height: 200,
            closeAction: 'hide',
            plain: true,
            modal: true,
            title: 'PAT:A 价格',
            autoLoad: {
                url: url,
                scripts: true
            },
            buttonAlign: 'center',
            buttons: [{
                text: '下一步',
                handler: function(){
                    if ((num_par == "" && price == "") || (num_par == "2" && price2 == "") || (num_par == "3" && price3 == "") || (num_par == "4" && price4 == "")) {
                        Ext.MessageBox.alert("提示", "没有价格信息！");
                    }
                    else {
                        singleClickWindow.hide();
                        ChooseTrip();
                    }
                }
            }, {
                text: '关闭',
                handler: function(){
                    singleClickWindow.hide();
                }
            }]
        });
        singleClickWindow.show();
        
    }
    //做申请
    clickOnApp = function(air_no_par, fromto_par, flyTime_par, arrTime_par, plane_par){
        if (trip_type == "wf") {
            Ext.MessageBox.alert("提示", "往返不能申请");
        }
        else if (trip_type == "lc") {
            Ext.MessageBox.alert("提示", "联程不能申请");
        }
        else {
            var positionCombo = new Ext.form.ComboBox({
                store: new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getPositionsBy?air_no=' + air_no_par + '&fromto=' + fromto_par
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root'
                    }, ['position', 'price'])
                }),
                fieldLabel: "舱位",
                name: 'app_position',
                loadingText: '正在加载...',
                displayField: 'position',
                valueField: 'position',
                mode: 'remote',
                triggerAction: 'all',
                hiddenName: 'app_position',
                emptyText: '所有',
                editable: false,
                allowBlank: false,
                blankText: '申请舱位必须选择',
                width: 50,
                //maxHeight: 150,
                //tabIndex: 4,
                listeners: {
                    select: function(combo, record, index){
                        priceField.setValue(record.data.price);
                    }
                }
            });
            var priceField = new Ext.form.NumberField({
                fieldLabel: '价格',
                name: 'app_price',
                allowBlank: false,
                blankText: '申请舱位的价格不能为空',
                anchor: '90%'
            });
            var appFormPanel = new Ext.form.FormPanel({
                //baseCls: 'x-plain',
                labelWidth: 45,
                labelAlign: 'right',
                frame: true,
                //url: "/orders/",
                items: [positionCombo, priceField]
            });
            //窗口
            var appClickWindow = new Ext.Window({
                title: '申请更低折扣/团体票',
                width: 280,
                height: 150,
                layout: 'fit',
                plain: true,
                bodyStyle: 'padding:5px;',
                buttonAlign: 'center',
                items: appFormPanel,
                buttons: [{
                    text: '申请',
                    handler: function(){
                        if (appFormPanel.form.isValid()) {
                            appClickWindow.hide();
                            
                            app_flag = "yes";
                            position = positionCombo.getValue();
                            price = priceField.getValue();
                            airNo = air_no_par;
                            fly_time = flyTime_par;
                            arr_time = arrTime_par;
                            plane_type = plane_par;
                            if (airNo.indexOf("*") == 0) {
                                airNo = airNo.substring(1);
                            }
                            fromto = fromto_par;
                            
                            ChooseTrip();
                        }
                    }
                }, {
                    text: '团体票',
                    //disabled: true,
                    handler: function(){
                        if (appFormPanel.form.isValid()) {
                            appClickWindow.hide();
                            
                            app_flag = "yes";
                            group_flag = "yes";
                            position = positionCombo.getValue();
                            price = priceField.getValue();
                            airNo = air_no_par;
                            fly_time = flyTime_par;
                            arr_time = arrTime_par;
                            plane_type = plane_par;
                            if (airNo.indexOf("*") == 0) {
                                airNo = airNo.substring(1);
                            }
                            fromto = fromto_par;
                            
                            ChooseTrip();
                        }
                    }
                }, {
                    text: '取消',
                    handler: function(){
                        appClickWindow.hide();
                    }
                }]
            });
            appClickWindow.show();
        }
    }
    //查询经停
    checkJT = function(air_no_par, date_par){
        var url = "/orders/checkJt?air_no="+air_no_par+"&date="+date_par;
        var checkJtWindow = new Ext.Window({
            layout: 'fit',
            width: 300,
            height: 150,
            closeAction: 'hide',
            plain: true,
            modal: true,
            title: 'FF:'+air_no_par+'/'+date_par,
            autoLoad: {
                url: url,
                scripts: true
            },
            buttonAlign: 'center',
            buttons: [{
                text: '关闭',
                handler: function(){
                    checkJtWindow.hide();
                }
            }]
        });
        checkJtWindow.show();
    }
    
    //******************转机联运查询结果 ZjlyGridDiv**********************
    var zjlyCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
        header: '编号',
        dataIndex: 'id',
        width: 50,
        hidden: true
    }, {
        header: '类型',
        dataIndex: 'trip_type',
        width: 60
    }, {
        header: '价格',
        dataIndex: 'price',
        width: 40
    }, {
        header: '始发地',
        dataIndex: 'from',
        renderer: airportRender,
        width: 80
    }, {
        header: '第一中转地',
        dataIndex: 'mid',
        renderer: airportRender,
        width: 80
    }, {
        header: '第二中转地',
        dataIndex: 'mid2',
        renderer: airportRender,
        width: 80
    }, {
        header: '目的地',
        dataIndex: 'to',
        renderer: airportRender,
        width: 80
    }, {
        header: '第三中转地',
        dataIndex: 'mid3',
        renderer: airportRender,
        width: 80
    }, {
        header: '第四中转地',
        dataIndex: 'mid4',
        renderer: airportRender,
        width: 80
    }, {
        header: '终到地',
        dataIndex: 'end',
        renderer: airportRender,
        width: 80
    }, {
        header: '航空公司',
        dataIndex: 'airways',
        width: 60
    }, {
        header: '舱位',
        dataIndex: 'position',
        width: 40
    }, {
        header: '舱位2',
        dataIndex: 'position2',
        width: 40
    }, {
        header: '舱位3',
        dataIndex: 'position3',
        width: 40
    }, {
        header: '舱位4',
        dataIndex: 'position4',
        width: 40
    }, {
        header: '生效日期',
        dataIndex: 'start_date',
        width: 70
    }, {
        header: '失效日期',
        dataIndex: 'end_date',
        width: 70
    }, {
        header: '代理费',
        dataIndex: 'rake_off',
        width: 50
    }, {
        header: '政策',
        dataIndex: 'policy',
        width: 150
    }]);
    zjlyCM.defaultSortable = true;
    var zjlyDS = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: "/index/searchZjly"
        }),
        reader: new Ext.data.JsonReader({
            root: 'root'
        }, [{
            name: 'id'
        }, {
            name: 'from_id'
        }, {
            name: 'mid_id'
        }, {
            name: 'mid_id2'
        },{
            name: 'to_id'
        }, {
            name: 'mid_id3'
        }, {
            name: 'mid_id4'
        }, {
            name: 'end_id'
        }, {
            name: 'from',
            mapping: 'from_airport.airport_name'
        }, {
            name: 'mid',
            mapping: 'mid_airport.airport_name'
        }, {
            name: 'mid2',
            mapping: 'mid_airport2.airport_name'
        }, {
            name: 'to',
            mapping: 'to_airport.airport_name'
        }, {
            name: 'mid3',
            mapping: 'mid_airport3.airport_name'
        }, {
            name: 'mid4',
            mapping: 'mid_airport4.airport_name'
        }, {
            name: 'end',
            mapping: 'end_airport.airport_name'
        }, {
            name: 'airways_id'
        }, {
            name: 'airways',
            mapping: 'airways.airways_name'
        }, {
            name: 'start_date'
        }, {
            name: 'end_date'
        }, {
            name: 'position'
        }, {
            name: 'position2'
        }, {
            name: 'position3'
        }, {
            name: 'position4'
        }, {
            name: 'price'
        }, {
            name: 'trip_type'
        }, {
            name: 'rake_off'
        }, {
            name: 'is_closed'
        }, {
            name: 'policy'
        }])
    });
    var ZjlyGridpanel = new Ext.grid.GridPanel({
        el: 'ZjlyGridDiv',
        ds: zjlyDS,
        cm: zjlyCM,
        loadMask: true,
        autoWidth: true,
        collapsible: true,
        animCollapse: true,
        height: 120,
        //frame: true,
        title: '转机联运政策'
    });
    ZjlyGridpanel.render();
    //zjlyDS.load();
    function airportRender(value){
        if (value.indexOf(" ")>0){
            return value.substring(value.indexOf(" ")+1);
        }else{
            return value;
        }
    }

    ZjlyGridpanel.on('rowdblclick', function(ZjlyGridpanel, rowIndex, e){
        var current_selected = zjlyDS.data.items[rowIndex].id;
        var zjlySrow = zjlyDS.getById(current_selected);
        var f_id = zjlySrow.get("from_id");
        var m_id = zjlySrow.get("mid_id");
        var m_id2 = zjlySrow.get("mid_id2");
        var t_id = zjlySrow.get("to_id");
        var m_id3 = zjlySrow.get("mid_id3");
        var m_id4 = zjlySrow.get("mid_id4");
        var n_id = zjlySrow.get("end_id");
        var a_id = zjlySrow.get("airways_id");
        var pos = zjlySrow.get("position");
        var pos2 = zjlySrow.get("position2");
        var pos3 = zjlySrow.get("position3");
        var pos4 = zjlySrow.get("position4");
        var t_type = zjlySrow.get("trip_type");
        //alert(f_id+"-"+m_id+"-"+m_id2+"-"+t_id+"-"+m_id3+"-"+m_id4+"-"+n_id+"-"+a_id+"-"+pos+"-"+pos2+"-"+pos3+"-"+pos4+"-"+t_type+"-"+phone_number);
        if (t_type=="往返"){
            t_type="wf";
        }else if (t_type=="联程往返"){
            t_type="wflc";
        }else if (t_type=="联程"){
            t_type="lc";
        }else{
            t_type="";
        }
        var tabs = Ext.getCmp('tabs');
        var url = '/index/checkAir2?phone_number='+phone_number+'&from_id='+f_id+
        '&mid_id='+m_id+'&mid_id2='+m_id2+'&to_id='+t_id+'&airways_id='+a_id+
        '&position='+pos+'&position2='+pos2+'&trip_type='+t_type;
        var check_air2_tab = Ext.getCmp('checkAir2_tab');
        if(check_air2_tab){
            check_air2_tab.setTitle('按政策查票');
            check_air2_tab.getUpdater().update(url);
            tabs.activate(check_air2_tab);
        }else{
            tabs.add({
                id: 'checkAir2_tab',
                title: '按政策查票',
                //disabled: true,
                autoLoad: {
                    url: url,
                    scripts: true
                },
                closable: true
            }).show();
        }
    });


    //******************航班查询结果 airlaneGrid**********************
    //var sm = new Ext.grid.CheckboxSelectionModel();
    //var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), sm, {
    var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
        header: '航班',
        dataIndex: 'no',
        width: 60,
        align: 'left'
    }, {
        header: '起飞(T)',
        dataIndex: 'flyTime',
        width: 50,
        align: 'left'
    }, {
        header: '舱位情况',
        dataIndex: 'status',
        width: 660,
        align: 'left'
    }, {
        header: '城市对',
        dataIndex: 'fromto',
        width: 60,
        align: 'left'
    }, {
        header: '到达(T)',
        dataIndex: 'arrTime',
        width: 50,
        align: 'left'
    }, {
        header: '机型',
        dataIndex: 'plane',
        width: 40,
        align: 'left'
    }, {
        header: '经停',
        dataIndex: 'other',
        width: 35,
        align: 'left'
    
    }]);
    cm.defaultSortable = true
    var airReader = new Ext.data.JsonReader({
        //totalProperty: 'totalProperty',
        root: 'root'
    }, [{
        name: 'no'
    }, {
        name: 'status'
    }, {
        name: 'fromto'
    }, {
        name: 'flyTime'
    }, {
        name: 'arrTime'
    }, {
        name: 'plane'
    }, {
        name: 'other'
    }]);
    
    //******************去程查询结果 airlaneGrid **********************
    var ds = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: "/index/searchAirLine?position="+position_only
        }),
        reader: airReader
    });
    var upDate1 = new Ext.Action({
        text: "前一天",
        iconCls: 'album',
        handler: function(){
            var ori_fly_date = fly_date;
            fly_date = getDateByNum(fly_date, -1);
            dateField.setValue(fly_date);
            this.setText("前一天(" + getDateByNum(fly_date, -1) + ")");
            nextDate1.setText("后一天(" + ori_fly_date + ")");
            ds.baseParams.date = fly_date;
            ds.reload();
        }
    });
    var nextDate1 = new Ext.Action({
        text: '后一天',
        iconCls: 'album',
        handler: function(){
            var ori_fly_date = fly_date;
            fly_date = getDateByNum(fly_date, 1);
            dateField.setValue(fly_date);
            this.setText("后一天(" + getDateByNum(fly_date, 1) + ")");
            upDate1.setText("前一天(" + ori_fly_date + ")");
            ds.baseParams.date = fly_date;
            ds.reload();
        }
    });
    var menubar = [upDate1, '-', nextDate1];
    var airlaneGridpanel = new Ext.grid.GridPanel({
        el: 'airlaneGrid',
        ds: ds,
        cm: cm,
        loadMask: true,
        autoWidth: true,
        collapsible: true,
        animCollapse: true,
        height: 460,
        //frame: true,
        title: '航班信息',
        bbar: menubar
    });
    /*
    airlaneGridpanel.getStore().on({
        //beforeload: function(){
        load: function(){
            var sum = this.reader.jsonData.root.length;
            //TODO 显示查询出的航班个数
            var result = this.reader.jsonData.info;
            if (result != "successful") {
                if (result == "") {
                    result = "没有结果";
                }
                Ext.MessageBox.alert("查询异常", "" + result);
            }
        }
    });
    */
    airlaneGridpanel.render();
    //ds.load();
    
    //******************返程\联程查询结果 airlaneGrid2 **********************
    var ds2 = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: "/index/searchAirLine?grid_no=2&position="+position_only2
        }),
        reader: airReader
    });
    var upDate2 = new Ext.Action({
        text: '前一天',
        iconCls: 'album',
        handler: function(){
            var ori_fly_date = fly_date2;
            fly_date2 = getDateByNum(fly_date2, -1);
            date2Field.setValue(fly_date2);
            this.setText("前一天(" + getDateByNum(fly_date2, -1) + ")");
            nextDate2.setText("后一天(" + ori_fly_date + ")");
            ds2.baseParams.date = fly_date2;
            ds2.reload();
        }
    });
    var nextDate2 = new Ext.Action({
        text: '后一天',
        iconCls: 'album',
        handler: function(){
            var ori_fly_date = fly_date2;
            fly_date2 = getDateByNum(fly_date2, 1);
            date2Field.setValue(fly_date2);
            this.setText("后一天(" + getDateByNum(fly_date2, 1) + ")");
            upDate2.setText("前一天(" + ori_fly_date + ")");
            ds2.baseParams.date = fly_date;
            ds2.reload();
        }
    });
    var menubar2 = [upDate2, '-', nextDate2];
    var airlaneGridpanel2 = new Ext.grid.GridPanel({
        el: 'airlaneGrid2',
        ds: ds2,
        cm: cm,
        loadMask: true,
        autoWidth: true,
        collapsible: true,
        animCollapse: true,
        height: 250,
        //frame: true,
        title: '返程/联程 航班信息',
        bbar: menubar2
    });
    /*
    airlaneGridpanel2.getStore().on({
        //beforeload: function(){
        load: function(){
            var result = this.reader.jsonData.info;
            if (result != "successful") {
                if (result == "") {
                    result = "没有结果";
                }
                Ext.MessageBox.alert("查询异常", "" + result);
            }
        }
    });
    */
    airlaneGridpanel2.render();
    if (trip_type==""){
        airlaneGridpanel2.setVisible(false);
    }
    //******************返程+联程查询结果 airlaneGrid3 **********************
    var ds3 = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: "/index/searchAirLine?grid_no=3&position="+position_only2
        }),
        reader: airReader
    });
    var upDate3 = new Ext.Action({
        text: "前一天",
        iconCls: 'album',
        handler: function(){
            var ori_fly_date = fly_date3;
            fly_date3 = getDateByNum(fly_date3, -1);
            date3Field.setValue(fly_date3);
            this.setText("前一天(" + getDateByNum(fly_date3, -1) + ")");
            nextDate3.setText("后一天(" + ori_fly_date + ")");
            ds3.baseParams.date = fly_date3;
            ds3.reload();
        }
    });
    var nextDate3 = new Ext.Action({
        text: '后一天',
        iconCls: 'album',
        handler: function(){
            var ori_fly_date = fly_date3;
            fly_date3 = getDateByNum(fly_date3, 1);
            date3Field.setValue(fly_date3);
            this.setText("后一天(" + getDateByNum(fly_date3, 1) + ")");
            upDate3.setText("前一天(" + ori_fly_date + ")");
            ds3.baseParams.date = fly_date3;
            ds3.reload();
        }
    });
    var menubar3 = [upDate3, '-', nextDate3];
    var airlaneGridpanel3 = new Ext.grid.GridPanel({
        el: 'airlaneGrid3',
        ds: ds3,
        cm: cm,
        loadMask: true,
        autoWidth: true,
        collapsible: true,
        animCollapse: true,
        height: 250,
        //frame: true,
        title: '回程 航班信息',
        bbar: menubar3
    });
    /*
    airlaneGridpanel3.getStore().on({
        //beforeload: function(){
        load: function(){
            var result = this.reader.jsonData.info;
            if (result != "successful") {
                if (result == "") {
                    result = "没有结果";
                }
                Ext.MessageBox.alert("查询异常", "" + result);
            }
        }
    });
    */
    airlaneGridpanel3.render();
    if (trip_type!="wflc"){
        airlaneGridpanel3.setVisible(false);
    }
    //******************返程+联程查询结果 airlaneGrid4 **********************
    var ds4 = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: "/index/searchAirLine?grid_no=4&position="+position_only
        }),
        reader: airReader
    });
    var upDate4 = new Ext.Action({
        text: "前一天",
        iconCls: 'album',
        handler: function(){
            var ori_fly_date = fly_date4;
            fly_date4 = getDateByNum(fly_date4, -1);
            date4Field.setValue(fly_date4);
            this.setText("前一天(" + getDateByNum(fly_date4, -1) + ")");
            nextDate4.setText("后一天(" + ori_fly_date + ")");
            ds4.baseParams.date = fly_date4;
            ds4.reload();
        }
    });
    var nextDate4 = new Ext.Action({
        text: '后一天',
        iconCls: 'album',
        handler: function(){
            var ori_fly_date = fly_date4;
            fly_date4 = getDateByNum(fly_date4, 1);
            date4Field.setValue(fly_date4);
            this.setText("后一天(" + getDateByNum(fly_date4, 1) + ")");
            upDate4.setText("前一天(" + ori_fly_date + ")");
            ds4.baseParams.date = fly_date4;
            ds4.reload();
        }
    });
    var menubar4 = [upDate4, '-', nextDate4];
    var airlaneGridpanel4 = new Ext.grid.GridPanel({
        el: 'airlaneGrid4',
        ds: ds4,
        cm: cm,
        loadMask: true,
        autoWidth: true,
        collapsible: true,
        animCollapse: true,
        height: 250,
        //frame: true,
        title: '回程联程 航班信息',
        bbar: menubar4
    });
    /*
    airlaneGridpanel4.getStore().on({
        //beforeload: function(){
        load: function(){
            var result = this.reader.jsonData.info;
            if (result != "successful") {
                if (result == "") {
                    result = "没有结果";
                }
                Ext.MessageBox.alert("查询异常", "" + result);
            }
        }
    });
    */
    airlaneGridpanel4.render();
    if (trip_type!="wflc"){
        airlaneGridpanel4.setVisible(false);
    }
    if (trip_type!=""){
        airlaneGridpanel.setHeight(250);
    }
    //一次定多张票
    function addMulOrder(){
        if (price && position) {
            var url = "/orders/addMulOrder?customerid=" + checkAir_customer_id + "&airNo=" + airNo + "&position=" + position + "&price=" + price + "&fly_time=" + fly_time + "&arr_time=" + arr_time + "&fromto=" + fromto + "&fly_date=" + fly_date + "&plane_type=" + plane_type;
            if (trip_type != "") {
                url += "&trip_type=" + trip_type + "&airNo2=" + airNo2 + "&position2=" + position2 + "&price2=" + price2 + "&fly_time2=" + fly_time2 + "&arr_time2=" + arr_time2 + "&fromto2=" + fromto2 + "&fly_date2=" + fly_date2 + "&plane_type2=" + plane_type2;
                if (trip_type == "wflc") {
                    url += "&airNo3=" + airNo3 + "&position3=" + position3 + "&price3=" + price3 + "&fly_time3=" + fly_time3 + "&arr_time3=" + arr_time3 + "&fromto3=" + fromto3 + "&fly_date3=" + fly_date3 + "&plane_type3=" + plane_type3;
                    url += "&airNo4=" + airNo4 + "&position4=" + position4 + "&price4=" + price4 + "&fly_time4=" + fly_time4 + "&arr_time4=" + arr_time4 + "&fromto4=" + fromto4 + "&fly_date4=" + fly_date4 + "&plane_type4=" + plane_type4;
                }
            }
            url += "&app_flag=" + app_flag + "&group_flag=" + group_flag;
            var tab_title = "订票";
            if (app_flag=="yes"){
                if (group_flag=="yes"){
                    tab_title = "团体票";
                }else{
                    tab_title = "做申请";
                }
            }
            app_flag = "";
            group_flag = "";
            var tabs = Ext.getCmp('tabs');
            var newOrderTab = Ext.getCmp('new_order');
            if (newOrderTab) {
                newOrderTab.setTitle(tab_title);
                newOrderTab.getUpdater().update(url);
                tabs.activate(newOrderTab);
            }
            else {
                tabs.add({
                    id: 'new_order',
                    title: tab_title,
                    //disabled: true,
                    autoLoad: {
                        url: url,
                        scripts: true
                    },
                    closable: true
                }).show();
            }
        }
        else {
            Ext.MessageBox.alert("提示", "没有价格或舱位信息");
        }
    }
    
    //显示已选择航班舱位信息
    var chooseWindow;
    function ChooseTrip(){
        if (chooseWindow) {
            chooseWindow.hide();
        }
        if (orderid == "" && trip_type != "wf" && trip_type != "lc" && trip_type != "wflc") {
            addMulOrder();
        }
        else {
            var winHeight = 150;
            var go = true;
            var myData = [];
            if (trip_type == "") {
                myData = [['航班信息', airNo, fromto, position, price, fly_date, fly_time, plane_type]];
            }
            else if (trip_type == "wf" || trip_type == "lc") {
                myData = [['来程航班', airNo, fromto, position, price, fly_date, fly_time, plane_type], ['返程/联程航班', airNo2, fromto2, position2, price2, fly_date2, fly_time2, plane_type2]];
            }
            else if (trip_type == "wflc") {
                winHeight = 200;
                myData = [['来程航班', airNo, fromto, position, price, fly_date, fly_time, plane_type], ['返/联程航班', airNo2, fromto2, position2, price2, fly_date2, fly_time2, plane_type2], ['回程航班', airNo3, fromto3, position3, price3, fly_date3, fly_time3, plane_type3], ['回程联程航班', airNo4, fromto4, position4, price4, fly_date4, fly_time4, plane_type4]];
            }
            
            var store = new Ext.data.SimpleStore({
                fields: [{
                    name: 'type'
                }, {
                    name: 'airno'
                }, {
                    name: 'fromto'
                }, {
                    name: 'position'
                }, {
                    name: 'price'
                }, {
                    name: 'fly_date'
                }, {
                    name: 'fly_time'
                }, {
                    name: 'plane_type'
                }]
            });
            store.loadData(myData);
            var grid = new Ext.grid.GridPanel({
                store: store,
                columns: [{
                    id: 'air',
                    header: "类型",
                    width: 120,
                    sortable: true,
                    dataIndex: 'type'
                }, {
                    header: "航班号",
                    width: 60,
                    sortable: true,
                    dataIndex: 'airno'
                }, {
                    header: "航程",
                    width: 60,
                    sortable: true,
                    dataIndex: 'fromto'
                }, {
                    header: "舱位",
                    width: 50,
                    sortable: true,
                    dataIndex: 'position'
                }, {
                    header: "价格",
                    width: 50,
                    sortable: true,
                    dataIndex: 'price'
                }, {
                    header: "日期",
                    width: 80,
                    sortable: true,
                    dataIndex: 'fly_date'
                }, {
                    header: "起飞时间",
                    width: 60,
                    sortable: true,
                    dataIndex: 'fly_time'
                }, {
                    header: "机型",
                    width: 40,
                    sortable: true,
                    dataIndex: 'plane_type'
                }],
                stripeRows: true,
                autoExpandColumn: 'air'
            });
            if (orderid == "") {
                chooseWindow = new Ext.Window({
                    title: '选定航程信息',
                    width: 550,
                    height: winHeight,
                    layout: 'fit',
                    plain: true,
                    bodyStyle: 'padding:5px;',
                    buttonAlign: 'center',
                    items: [grid],
                    buttons: [{
                        text: '订票',
                        handler: function(){
                            go = true;
                            if (airNo == "" || fly_date == "" || fromto == "") {
                                Ext.MessageBox.alert('提示', '请选择来程航班.');
                                go = false;
                            }
                            else if (position == "" || price == "") {
                                Ext.MessageBox.alert('提示', '请选择来程航班的舱位.');
                                go = false;
                            }
                            else if (trip_type != "") {
                                if (airNo2 == "" || fly_date2 == "" || fromto2 == "") {
                                    Ext.MessageBox.alert('提示', '请选择返程、联程航班.');
                                }
                                else if (position2 == "" || price2 == "") {
                                    Ext.MessageBox.alert('提示', '请选择返程、联程航班的舱位.');
                                    go = false;
                                }
                                if (go && trip_type == "wflc") {
                                    if (airNo3 == "" || fly_date3 == "" || fromto3 == "") {
                                        Ext.MessageBox.alert('提示', '请选择回程航班.');
                                        go = false;
                                    }
                                    else if (position3 == "" || price3 == "") {
                                        Ext.MessageBox.alert('提示', '请选择回程航班的舱位.');
                                        go = false;
                                    }
                                    else if (airNo4 == "" || fly_date4 == "" || fromto4 == "") {
                                        Ext.MessageBox.alert('提示', '请选择回程联程航班.');
                                        go = false;
                                    }
                                    else if (position4 == "" || price4 == "") {
                                        Ext.MessageBox.alert('提示', '请选择回程联程航班的舱位.');
                                        go = false;
                                    }
                                }
                            }
                            if (go) {
                                chooseWindow.hide();
                                addMulOrder();
                            }
                        }
                    }, {
                        text: '关闭',
                        handler: function(){
                            chooseWindow.hide();
                        }
                    }]
                })
            }
            else {
                chooseWindow = new Ext.Window({
                    title: '选定航程信息',
                    width: 550,
                    height: winHeight,
                    layout: 'fit',
                    plain: true,
                    bodyStyle: 'padding:5px;',
                    buttonAlign: 'center',
                    items: [grid],
                    buttons: [{
                        id: 'modAirLineButton',
                        text: '提交修改',
                        handler: function(){
                            this.disable();
                            go = true;
                            if (airNo == "" || fly_date == "" || fromto == "") {
                                Ext.MessageBox.alert('提示', '请选择来程航班.');
                                go = false;
                            }
                            else if (position == "" || price == "") {
                                Ext.MessageBox.alert('提示', '请选择来程航班的舱位.');
                                go = false;
                            }
                            else if (trip_type != "") {
                                if (airNo2 == "" || fly_date2 == "" || fromto2 == "") {
                                    Ext.MessageBox.alert('提示', '请选择返程、联程航班.');
                                }
                                else if (position2 == "" || price2 == "") {
                                    Ext.MessageBox.alert('提示', '请选择返程、联程航班的舱位.');
                                    go = false;
                                }
                                if (go && trip_type == "wflc") {
                                    if (airNo3 == "" || fly_date3 == "" || fromto3 == "") {
                                        Ext.MessageBox.alert('提示', '请选择回程航班.');
                                        go = false;
                                    }
                                    else if (position3 == "" || price3 == "") {
                                        Ext.MessageBox.alert('提示', '请选择回程航班的舱位.');
                                        go = false;
                                    }
                                    else if (airNo4 == "" || fly_date4 == "" || fromto4 == "") {
                                        Ext.MessageBox.alert('提示', '请选择回程联程航班.');
                                        go = false;
                                    }
                                    else if (position4 == "" || price4 == "") {
                                        Ext.MessageBox.alert('提示', '请选择回程联程航班的舱位.');
                                        go = false;
                                    }
                                }
                            }
                            if (go) {
                                var par = "orderid=" + orderid + "&airNo=" + airNo + "&position=" + position + "&price=" + price + "&fly_time=" + fly_time + "&arr_time=" + arr_time + "&fromto=" + fromto + "&fly_date=" + fly_date + "&plane_type=" + plane_type;
                                if (trip_type != "") {
                                    par += "&trip_type=" + trip_type + "&airNo2=" + airNo2 + "&position2=" + position2 + "&price2=" + price2 + "&fly_time2=" + fly_time2 + "&arr_time2=" + arr_time2 + "&fromto2=" + fromto2 + "&fly_date2=" + fly_date2 + "&plane_type2=" + plane_type2;
                                    if (trip_type == "wflc") {
                                        par += "&airNo3=" + airNo3 + "&position3=" + position3 + "&price3=" + price3 + "&fly_time3=" + fly_time3 + "&arr_time3=" + arr_time3 + "&fromto3=" + fromto3 + "&fly_date3=" + fly_date3 + "&plane_type3=" + plane_type3;
                                        par += "&airNo4=" + airNo4 + "&position4=" + position4 + "&price4=" + price4 + "&fly_time4=" + fly_time4 + "&arr_time4=" + arr_time4 + "&fromto4=" + fromto4 + "&fly_date4=" + fly_date4 + "&plane_type4=" + plane_type4;
                                    }
                                }
                                Ext.Ajax.request({
                                    url: '/orders/saveModAirline',
                                    params: par,
                                    method: 'POST',
                                    success: function(result, request){
                                        if (result.responseText.indexOf("成功") >= 0) {
                                            chooseWindow.hide();
                                            Ext.MessageBox.alert('操作成功', result.responseText + '<br> 将转回来电显示页面');
                                            //刷新
                                            window.location.href = "/index/phoneshow?id=" + checkAir_customer_id;
                                        /*
                                            var url = '/customers/customerInfoByID?id=' + checkAir_customer_id;
                                            var tabs = Ext.getCmp('tabs');
                                            var customer_info_tab = Ext.getCmp('phoneshow_tab0');
                                            if (customer_info_clikced){
                                                customer_info_tab.getUpdater().update(url);
                                            }else{
                                                customer_info_tab.autoLoad.url=url;
                                            }
                                            tabs.activate(customer_info_tab);
                                            */
                                        }
                                        else {
                                            Ext.MessageBox.alert('操作失败', result.responseText);
                                            var s_button = Ext.getCmp('modAirLineButton');
                                            s_button.enable();
                                        }
                                    },
                                    failure: function(result, request){
                                        Ext.MessageBox.alert('操作信息', '修改航班信息失败');
                                        var s_button = Ext.getCmp('modAirLineButton');
                                        s_button.enable();
                                    }
                                });
                            }
                        }
                    }, {
                        text: '关闭',
                        handler: function(){
                            chooseWindow.hide();
                        }
                    }]
                })
            }
            chooseWindow.show();
        }
    }
    
})
